﻿using System.Linq;
using FacialClub.Models.Entities;
using FacialClub.Models.Interfaces;
namespace FacialClub.Models.Repositories
{
    /// <summary>
    /// Access Type Repository
    /// </summary>
    public class AccessTypeRepository : IAccessTypeRepository
    {
        readonly FacialClubEntities _db = new FacialClubEntities();

        /// <summary>
        /// Get Access Type Details by Title
        /// </summary>
        /// <param name="strQuery"></param>
        /// <returns></returns>
        public IQueryable<AccessType> FindAccessTypeByName(string strQuery)
        {
            return _db.AccessTypes.Where(d => d.AccessTypeName.Contains(strQuery));
        }

        /// <summary>
        /// Get All Access Type
        /// </summary>
        /// <returns></returns>
        public IQueryable<AccessType> FindAllAccessType()
        {
            return _db.AccessTypes;
        }

        /// <summary>
        /// Get Access Type by Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public AccessType GetAccessTypeById(int id)
        {
            return _db.AccessTypes.SingleOrDefault(d => d.AccessTypeId == id);
        }

        /// <summary>
        /// Add Access Type in the Database
        /// </summary>
        /// <param name="accessType"></param>
        public void Add(AccessType accessType)
        {
            _db.AccessTypes.AddObject(accessType);
        }

        /// <summary>
        /// Delete Access Type from Database
        /// </summary>
        /// <param name="accessType"></param>
        public void Delete(AccessType accessType)
        {
            _db.AccessTypes.DeleteObject(accessType);
        }

        /// <summary>
        /// Save Access Type in the database
        /// </summary>
        public void Save()
        {
            _db.SaveChanges();
        }
    }
}